﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Application;
using MySqlConnection;

namespace Data
{
    public static class ParagraphData
    {
        public static void AddParagraph(VOParagraph paragraph)
        {
            DBContainer dbCont = MySqlContext.DataContext;
            ParagraphClass newPrg = new ParagraphClass();

            newPrg.title = paragraph.Title;
            newPrg.description = paragraph.Description;
            newPrg.content = paragraph.Content;
            dbCont.AddParagraph(newPrg);
        }
        public static VOParagraph GetParagraphById(string id)
        {
            VOParagraph paragraph = new VOParagraph();
            DBContainer dbCont = MySqlContext.DataContext;
            ParagraphClass paragraphItem = dbCont.GetParagraphById(id);
            paragraph.ID = paragraphItem.id;
            paragraph.Title = paragraphItem.title;
            paragraph.Content = paragraphItem.content;
            paragraph.Description = paragraphItem.description;
            return paragraph;
        }

        public static List<VOParagraph> GetAllParagraphs()
        {
            List<VOParagraph> allParagraphs = new List<VOParagraph>();
            DBContainer dbCont = MySqlContext.DataContext;
            List<ParagraphClass> paragraphListItems = dbCont.GetAllParagraphs();
            foreach (ParagraphClass paragraphItem in paragraphListItems)
            {
                VOParagraph paragraph = new VOParagraph();
                paragraph.ID = paragraphItem.id;
                paragraph.Title = paragraphItem.title;
                paragraph.Content = paragraphItem.content;
                paragraph.Description = paragraphItem.description;
                allParagraphs.Add(paragraph);
            }
            return allParagraphs;
        }

        public static void UpdateParagraph(VOParagraph paragraph)
        {
            ParagraphClass paragraphItem = new ParagraphClass();
            DBContainer dbCont = MySqlContext.DataContext;
            paragraphItem.id = paragraph.ID;
            paragraphItem.title = paragraph.Title;
            paragraphItem.content = paragraph.Content;
            paragraphItem.description = paragraph.Description;
            dbCont.UpdateParagraph(paragraphItem);
        }
    }
}
